<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>this的介绍</title>
  </head>
  <body>
    <script>
      var name = "张三";
      function test(a, b) {
        alert(this.name + "_" + a + "_" + b);
      }
      var obj = {
        name: "李四",
      };
      // 改变this的指向,并执行这个函数
      //   区别：call(对象,a,b,c...)
      //        apply(对象,[a,b,c...])
      test.call(obj, 1, 2);
      test.apply(obj, [1, 2]);
      //   bind只是改变this的指向，并返回改变this指向的函数
      const func = test.bind(obj, 1, 2);
      console.log(func());
    </script>
  </body>
</html>
